﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using UCL.Powersource.Analysis;

namespace UCL.Powersource.Statistics
{
    /// <summary>
    /// Class for velocity calculation
    /// </summary>
    [Export(typeof(IStatistic))]
    [DataContract(IsReference = true)]
    public class VelocityStatistics : EffortStatisticsBase
    {
        [ExcludeFromCodeCoverage]
        public override string Label        
        {
            get { return "Velocity"; }
        }

        [ExcludeFromCodeCoverage]
        public override string Description  
        {
            get { return "Velocity of a stat in an iteration"; }
        }

        [ExcludeFromCodeCoverage]
        public override string Name  
        {
            get { return "Velocity"; }
        }

        public static readonly Guid CN_Statistic_Guid = new Guid("0EF319C0-72AA-48A1-B7E5-98FB31885F9B");
        [ExcludeFromCodeCoverage]
        public override Guid Statistic_Guid
        {
            get { return CN_Statistic_Guid; }
        }

        [DataMember]
        private readonly string _QueryString = "Select [ID], [Iteration Path], [State], [Effort] From WorkItems Where [Work Item Type] = 'Product Backlog Item'";       // Declaration of the _QueryString which returns work item ID, iteration path, state and effort

        protected override string QueryString { get { return _QueryString; } }

        [DataMember]
        private readonly string _WIType = "";     

        protected override string WIType { get { return _WIType; } }

        [DataMember]
        private readonly string _State = "Done";     

        protected override string State { get { return _State; } }

        [DataMember]
        private readonly string _WasEver = "";     

        protected override string WasEver { get { return _WasEver; } }

        /// <summary>
        /// Class for validation of the work item state
        /// </summary>
        /// <param name="item">Work item</param>
        /// <returns>Work item state</returns>
        protected override bool ValidState(WorkItem item)
        {
            return (string)item.Fields["State"].Value == State;
        }
     }
}
